<cfcomponent output="false">

	<cffunction name="read" output="false" access="public" returntype="virtualfooddrive-inf.com.User">
		<cfargument name="id" required="true">
		<cfset var qRead="">
		<cfset var obj="">

		<cfquery username="#request.username#" password="#request.password#" name="qRead" datasource="nwharvest">
			select 	ID, EMAIL, PASSWORD, ADDRESS_ID, ROLE_ID, FNAME, 
					LNAME, CAT_ID, ACTIVE, IS_DELETED
			from dbo.USERS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />
		</cfquery>

		<cfscript>
			obj = createObject("component", "virtualfooddrive-inf.com.User").init();
			obj.ID = qRead.ID;
			obj.EMAIL = qRead.EMAIL;
			obj.PASSWORD = qRead.PASSWORD;
			obj.ADDRESS_ID = qRead.ADDRESS_ID;
			obj.ROLE_ID = qRead.ROLE_ID;
			obj.FNAME = qRead.FNAME;
			obj.LNAME = qRead.LNAME;
			obj.CAT_ID = qRead.CAT_ID;
			obj.ACTIVE = qRead.ACTIVE;
			obj.IS_DELETED = qRead.IS_DELETED;		
			
			return obj;
		</cfscript>
	</cffunction>

	<cffunction name="create" output="false" access="public">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.User">
		<cfset var qCreate="">

		<cfset var local1=arguments.bean.EMAIL>
		<cfset var local2=arguments.bean.PASSWORD>
		<cfset var local3=arguments.bean.ADDRESS_ID>
		<cfset var local4=arguments.bean.ROLE_ID>
		<cfset var local5=arguments.bean.FNAME>
		<cfset var local6=arguments.bean.LNAME>
		<cfset var local7=arguments.bean.CAT_ID>
		<cfset var local8=arguments.bean.ACTIVE>
		<cfset var local9=arguments.bean.IS_DELETED>

		<cftransaction isolation="read_committed">
			<cfquery username="#request.username#" password="#request.password#" name="qCreate" datasource="nwharvest">
				insert into dbo.USERS(EMAIL, PASSWORD, ADDRESS_ID, ROLE_ID, FNAME, LNAME, CAT_ID, ACTIVE, IS_DELETED)
				values (
					<cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local2#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local3#" cfsqltype="CF_SQL_INTEGER" null="#iif((local3 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local4#" cfsqltype="CF_SQL_INTEGER" null="#iif((local4 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local5#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local6#" cfsqltype="CF_SQL_VARCHAR" />,
					<cfqueryparam value="#local7#" cfsqltype="CF_SQL_INTEGER" null="#iif((local7 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local8#" cfsqltype="CF_SQL_BIT" null="#iif((local8 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local9#" cfsqltype="CF_SQL_BIT" null="#iif((local9 eq ""), de("yes"), de("no"))#" />
				)
				select @@Identity as pkID
			</cfquery>

		</cftransaction>

		<cfscript>
			arguments.bean.ID = qCreate.pkID;
		</cfscript>
		<cfreturn arguments.bean />
	</cffunction>

	<cffunction name="update" output="false" access="public">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.User">
		<cfset var qUpdate="">

		<cfquery username="#request.username#" password="#request.password#" name="qUpdate" datasource="nwharvest" result="status">
			update dbo.USERS
			set EMAIL = <cfqueryparam value="#arguments.bean.EMAIL#" cfsqltype="CF_SQL_VARCHAR" />,
				PASSWORD = <cfqueryparam value="#arguments.bean.PASSWORD#" cfsqltype="CF_SQL_VARCHAR" />,
				ADDRESS_ID = <cfqueryparam value="#arguments.bean.ADDRESS_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.ADDRESS_ID eq ""), de("yes"), de("no"))#" />,
				ROLE_ID = <cfqueryparam value="#arguments.bean.ROLE_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.ROLE_ID eq ""), de("yes"), de("no"))#" />,
				FNAME = <cfqueryparam value="#arguments.bean.FNAME#" cfsqltype="CF_SQL_VARCHAR" />,
				LNAME = <cfqueryparam value="#arguments.bean.LNAME#" cfsqltype="CF_SQL_VARCHAR" />,
				CAT_ID = <cfqueryparam value="#arguments.bean.CAT_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.CAT_ID eq ""), de("yes"), de("no"))#" />,
				ACTIVE = <cfqueryparam value="#arguments.bean.ACTIVE#" cfsqltype="CF_SQL_BIT" null="#iif((arguments.bean.ACTIVE eq ""), de("yes"), de("no"))#" />,
				IS_DELETED = <cfqueryparam value="#arguments.bean.IS_DELETED#" cfsqltype="CF_SQL_BIT" null="#iif((arguments.bean.IS_DELETED eq ""), de("yes"), de("no"))#" />
			where ID = <cfqueryparam value="#arguments.bean.ID#" cfsqltype="CF_SQL_INTEGER">
		</cfquery>
		<cfreturn arguments.bean />
	</cffunction>

	<cffunction name="delete" output="false" access="public" returntype="void">
		<cfargument name="bean" required="true" type="virtualfooddrive-inf.com.User">
		<cfset var qDelete="">

		<cfquery username="#request.username#" password="#request.password#" name="qDelete" datasource="nwharvest" result="status">
			delete
			from dbo.USERS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.ID#" />
		</cfquery>

	</cffunction>

</cfcomponent>